﻿using System;
using System.Collections.Generic;
using System.Text;

namespace SharpSoft.Geometries.Structs
{
    /// <summary>
    /// 三角形
    /// </summary>
    public struct Trigon
    {
        /// <summary>
        /// 使用三边长初始化三角形结构
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <param name="c"></param>
        public Trigon(double a, double b, double c)
        {
            if (a <= 0 || b <= 0 || c <= 0 || a + b <= c || b + c <= a || a + c <= b)
            {
                throw new Exception("无效的三角形三边长度。");
            }
            A = a; B = b; C = c;
        }
        /// <summary>
        /// 使用两边长及其夹角初始化三角形
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <param name="angle"></param>
        public Trigon(double a, double b, Radian angle)
        {
            A = a; B = b;
            C = Math.Sqrt(a.Pow() + b.Pow() - 2 * a * b * Math.Cos((double)angle));
        }
        /// <summary>
        /// 三角形的第一条边长
        /// </summary>
        public double A { get; set; }
        /// <summary>
        /// 三角形的第二条边长
        /// </summary>
        public double B { get; set; }
        /// <summary>
        /// 三角形的第三条边长
        /// </summary>
        public double C { get; set; }

        /// <summary>
        /// AB边的夹角,边C的对角
        /// </summary>
        public Radian Angle_C
        {
            get
            {
                var v = (A.Pow() + B.Pow() - C.Pow()) / (2 * A * B);
                return new Radian(Math.Acos(v));
            }
        }
        /// <summary>
        /// AC边的夹角,边B的对角
        /// </summary>
        public Radian Angle_B
        {
            get
            {
                var v = (A.Pow() + C.Pow() - B.Pow()) / (2 * A * C);
                return new Radian(Math.Acos(v));
            }
        }
        /// <summary>
        /// BC边的夹角,边A的对角
        /// </summary>
        public Radian Angle_A
        {
            get
            {
                var v = (B.Pow() + C.Pow() - A.Pow()) / (2 * B * C);
                return new Radian(Math.Acos(v));
            }
        }
    }
}
